#include "stdafx.h"

#include "SharpSDL.h"
#include "Joystick.h"

using namespace SharpSDL::ManagedSDL;

SharpSDL::SDLInitReturn SharpSDL::SDL::Init(SDLInitFlags flags)
{
	Uint32 flag = (unsigned int)flags;
	if (SDL_Init(flag) == 0)
	{
		SharpSDL::ManagedSDL::Joystick::SetJoystickEvent(SharpSDL::ManagedSDL::Joystick::JoystickEvent::Enabled);
		return SharpSDL::SDLInitReturn::Success;
	} else {
		return SharpSDL::SDLInitReturn::Failure;
	}
	return SharpSDL::SDLInitReturn::Failure;
}

SharpSDL::SDLInitReturn SharpSDL::SDL::InitSubSystem(SDLInitFlags flags)
{
	Uint32 flag = (unsigned int)flags;
	if (SDL_InitSubSystem(flag) == 0)
		return SharpSDL::SDLInitReturn::Success;
	else
		return SharpSDL::SDLInitReturn::Failure;
	return SharpSDL::SDLInitReturn::Failure;
}

void SharpSDL::SDL::QuitSubSystem(SDLQuitFlags flags)
{
	Uint32 flag = (unsigned int)flags;
	SDL_QuitSubSystem(flag);
}

void SharpSDL::SDL::Quit()
{
	SDL_Quit();
	return;
}

char* SharpSDL::SDL::Error::GetLastError(void)
{
	return SDL_GetError();
}

void SharpSDL::SDL::Error::SetError(ErrorCode error)
{
	SDL_Error((SDL_errorcode)error);
	return;
}

void SharpSDL::SDL::Error::ClearError(void)
{
	SDL_ClearError();
	return;
}

int SharpSDL::SDL::ApplicationStatus::AppStatus(void)
{
	return SDL_GetAppState();
}

bool SharpSDL::SDL::ApplicationStatus::AppMouseFocus(void)
{
	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == SDL_APPMOUSEFOCUS)
		return true;
	else
		return false;
}

bool SharpSDL::SDL::ApplicationStatus::AppInputFocus(void)
{
	if ((SDL_GetAppState() & SDL_APPINPUTFOCUS) == SDL_APPINPUTFOCUS)
		return true;
	else
		return false;
}

bool SharpSDL::SDL::ApplicationStatus::AppActive(void)
{
	if ((SDL_GetAppState() & SDL_APPACTIVE) == SDL_APPACTIVE)
		return true;
	else
		return false;
}